package com.gxa.meiye.portal.controller.zy;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.pojo.domain.Consumer;

import com.gxa.meiye.portal.hread.UserThreadLocal;
import com.gxa.meiye.portal.service.zy.LogOutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-25  15:10
 */
@RestController
@Api(value = "退出",tags = "退出接口")
@RequestMapping("/logout")
public class LogOutController {
    @Autowired
    private LogOutService logOutService;
    //退出接口删掉token
    @ApiOperation(value = "退出")
    @PostMapping("/delete")
    public Map del() throws JsonProcessingException {
        //从本地线程池获取当前消费者电话
        Object o = UserThreadLocal.get();
        ObjectMapper objectMapper=new ObjectMapper();
        Consumer consumer = objectMapper.readValue(o.toString(), Consumer.class);
        String phone = consumer.getPhone();
        System.out.println(phone);
        boolean del = logOutService.del(phone);
        JsonResult jsonResult=new JsonResult();
        if (del){
            jsonResult.setCode("1");
            jsonResult.setMsg("退出成功");
            return jsonResult.getMap();
        }
        return jsonResult.getMap();
    }
}
